package com.leyou.item.mapper;

import com.leyou.common.mapper.BaseMapper;
import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: wangzibeng
 * Date: 2019/4/28 0028
 * Time: 16:51
 */

@Repository
public interface BrandMapper extends BaseMapper<Brand> {
    /**
     * 商品分类和品牌的中间表
     *
     * @param bid
     * @param cid
     * @return
     */
    @Insert("insert into tb_category_brand (category_id,brand_id) values(#{cid},#{bid})")
    int insertCategoryBrand(@Param("bid") Long bid, @Param("cid") Long cid);

    /**
     * 根据bid 删除所有的cid
     *
     * @param bid 品牌id
     * @return
     */
    @Delete("delete from tb_category_brand where brand_id=#{bid}")
    int deleteCategoryCids(@Param("bid") Long bid);

    @Select("SELECT brand_id FROM tb_category_brand WHERE category_id = #{cid}")
    List<Long> getBrandIdsByCid(@Param("cid") Long cid);
}
